﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.tutorial.chapter {
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.events.windows.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.controllers.startup.*;
    import net.wooga.pets.views.tutorial.*;

    public class TutorialFountainMediator extends TutorialMediator {

        private var _localMapping:Dictionary;

        public function TutorialFountainMediator():void{
            this._localMapping = new Dictionary();
            this._localMapping[TutorialModel.FOUNTAIN_START_TUTORIAL] = this.onFountainStart;
            this._localMapping[TutorialModel.FOUNTAIN_CLICK_ON_SHOP] = this.onClickShopForFountain;
            this._localMapping[TutorialModel.FOUNTAIN_CHOOSE_ROOM] = this.onChooseFountain;
            this._localMapping[TutorialModel.FOUNTAIN_PLACE_ROOM] = this.onPlaceFountain;
            this._localMapping[TutorialModel.FOUNTAIN_START_TUTORIAL_ELDER] = this.onFountainStartElder;
            this._localMapping[TutorialModel.FOUNTAIN_WELCOME_ELDER] = this.onWelcomeElder;
            this._localMapping[TutorialModel.FOUNTAIN_ELDER_WALK_TO_FOUNTAIN] = this.onElderWalkToFountain;
            this._localMapping[TutorialModel.FOUNTAIN_CLICK_ON_ELDER] = this.clickOnElder;
            this._localMapping[TutorialModel.FOUNTAIN_SHOW_ELDER_BUBBLE] = this.onShowElderBubble;
            this._localMapping[TutorialModel.FOUNTAIN_CLICK_ON_SYMBOL] = this.onClickOnSymbol;
            this._localMapping[TutorialModel.FOUNTAIN_SYMBOL_TO_INVENTORY] = this.onSymbolToInventory;
            this._localMapping[TutorialModel.FOUNTAIN_ZOOM_TO_ELDER] = this.onZoomToElder;
            this._localMapping[TutorialModel.FOUNTAIN_TREAT_ELDER] = this.onTreatElder;
            this._localMapping[TutorialModel.FOUNTAIN_SHOW_TREAT_ELDER_BUBBLE] = this.onTreatElderBubble;
            this._localMapping[TutorialModel.FOUNTAIN_WAIT_FOR_ELDER_TREATMENT] = this.onWaitForElderTreatment;
            this._localMapping[TutorialModel.FOUNTAIN_RELEASE_ELDER] = this.onReleaseElder;
            this._localMapping[TutorialModel.FOUNTAIN_SHARE] = this.onShare;
            this._localMapping[TutorialModel.FOUNTAIN_FINISH_TUTORIAL] = this.onFinish;
        }
        override public function onRegister():void{
            super.onRegister();
        }
        override protected function onStateChange(_arg1:GameEvent=null):void{
            super.onStateChange(_arg1);
            var _local2:Function = this._localMapping[tutorialModel.state];
            if (_local2 != null){
                _local2();
            };
        }
        public function onFountainStart():void{
            var _local1:Boolean = world.hasAreaType(GameConstants.TYPE_FOUNTAIN);
            if (_local1){
                tutorialModel.state = TutorialModel.FOUNTAIN_FINISH_TUTORIAL;
                return;
            };
            eventMap.mapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onClickShopForFountain():void{
            roomSlotsModel.tempAvailableRoomSlots = 1;
            dispatch(new UserModelEvent(UserModelEvent.ON_MODEL_CHANGED));
            centerGameView(GameViewModel.SCALE_4X4);
            eventMap.unmapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            mapEvent(EventConstants.ON_OPEN_CUSTOMIZE_MENU, TutorialModel.FOUNTAIN_CHOOSE_ROOM);
            dispatch(new InfoEvent(EventConstants.SELECT_SHOP_CATEGORY, null, {category:"rooms"}));
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_fountain_open_shop");
            focusShopButton();
        }
        public function onChooseFountain():void{
            roomSlotsModel.tempAvailableRoomSlots = 1;
            dispatch(new InfoEvent(EventConstants.SET_BUILD_CANCELATION, null, false));
            centerGameView(GameViewModel.SCALE_4X4);
            eventMap.unmapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            mapEvent(EventConstants.ON_START_DRAGGING_CUSTOMIZE_ITEM, TutorialModel.FOUNTAIN_PLACE_ROOM);
            eventMap.mapListener(eventDispatcher, EventConstants.TRY_TO_CANCEL_BUILDMODE, mapTryToCancel);
            if (tutorialModel.fountainShopItemPosition){
                sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_fountain_choose");
                tutorial.showFocusArrow((tutorialModel.fountainShopItemPosition.x - 10), (tutorialModel.fountainShopItemPosition.y - 170));
                tutorial.showClickBlocker((tutorialModel.fountainShopItemPosition.x + 30), (tutorialModel.fountainShopItemPosition.y + 30), 0.3);
                tutorial.showSpotlight((tutorialModel.fountainShopItemPosition.x + 30), (tutorialModel.fountainShopItemPosition.y + 30), 0.5);
            } else {
                tutorial.hideFocusArrow();
                tutorial.showClickBlocker();
                tutorial.hideSpotlight();
                setTimeout(this.onChooseFountain, 1000);
            };
        }
        public function onPlaceFountain():void{
            roomSlotsModel.tempAvailableRoomSlots = 0;
            mapEvent(EventConstants.CREATE_ROOM, TutorialModel.FOUNTAIN_FINISH_TUTORIAL);
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
            tutorial.hideFocusArrow();
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
        }
        public function onFountainStartElder():void{
            dispatch(new InfoEvent(EventConstants.INIT_TREE));
            sessionModel.hasFountain = true;
            centerGameView(GameViewModel.SCALE_4X4);
            mapEvent(EventConstants.ON_ARRIVAL_AT_RECEPTION, TutorialModel.FOUNTAIN_WELCOME_ELDER);
        }
        public function onWelcomeElder():void{
            centerGameView(GameViewModel.SCALE_4X4);
            dispatch(new InfoEvent(EventConstants.CLOSE_SHOP, null));
            var _local1:ITreatable = getRoomByType(GameConstants.TYPE_RECEPTION).machine.patient;
            if (((!(_local1)) || (!((_local1.diseaseName == WorldConstants.DISEASE_OLD))))){
                tutorialModel.state = TutorialModel.FOUNTAIN_START_TUTORIAL;
                return;
            };
            dispatch(new Event(EventConstants.HIDE_MISSIONS));
            mapEvent(EventConstants.ON_PATIENT_ACCEPTED, TutorialModel.FOUNTAIN_ELDER_WALK_TO_FOUNTAIN);
            gameStateModel.isFacadeVisible = false;
            var _local2:String = world.getRoomIdsOfType(GameConstants.TYPE_RECEPTION)[0];
            var _local3:IRoom = IRoom(world.getRoomById(_local2));
            var _local4:Rectangle = _local3.viewRectangle;
            var _local5:Number = (_local4.x + ((3 / 4) * _local4.width));
            var _local6:Number = (_local4.y + ((1 / 2) * _local4.height));
            tutorial.showFocusArrow((_local5 + 230), (_local6 - 40), 90);
            tutorial.showClickBlocker(_local5, _local6, 0.4);
            tutorial.showSpotlight(_local5, _local6, 0.4);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_fountain_elderappears");
        }
        public function onElderWalkToFountain():void{
            mapEvent(EventConstants.HIDE_VIEW, TutorialModel.FOUNTAIN_CLICK_ON_ELDER);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"f20_elder"}));
            tutorial.showClickBlocker();
            tutorial.hideFocusArrow();
            tutorial.hideSpotlight();
        }
        public function clickOnElder():void{
            var _local2:Object;
            centerGameView(GameViewModel.SCALE_4X4);
            mapEvent(EventConstants.SHOW_POPUP, TutorialModel.FOUNTAIN_SHOW_ELDER_BUBBLE);
            var _local1:IRoom = getRoomByType(GameConstants.TYPE_FOUNTAIN);
            if (((((_local1.machine.patient) && (_local1.machine.patient.currentTreatment))) && (_local1.machine.patient.currentTreatment.symbols))){
                _local2 = _local1.machine.patient.currentTreatment.symbols;
                if (symbolModel.hasSymbols(_local2)){
                    tutorialModel.state = TutorialModel.FOUNTAIN_ZOOM_TO_ELDER;
                    return;
                };
            };
            dispatch(new InfoEvent(EventConstants.ZOOM_IN_ROOM, String(getRoomSlotByType(GameConstants.TYPE_FOUNTAIN).id)));
            tutorial.showFocusArrow(130, 280, -90);
            tutorial.showBlockingSpotlight(380, 225, 1.1);
            sunModel.simpleMessage = languageModel.getTextByKey("general_tutorial_fountain_clickonelder");
        }
        public function onShowElderBubble():void{
            mapEvent(EventConstants.FOUNTAIN_CLOSED, TutorialModel.FOUNTAIN_CLICK_ON_SYMBOL);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"f30_elder_in_foy"}));
            onRemoveOverlay();
        }
        public function onClickOnSymbol():void{
            centerGameView(GameViewModel.SCALE_4X4);
            mapEvent(EventConstants.UPDATE_SYMBOLS, TutorialModel.FOUNTAIN_SYMBOL_TO_INVENTORY);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"f40_collect"}));
            tutorial.showFocusArrow(483, 270, -90);
            tutorial.showBlockingSpotlight(698, 235, 0.5);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_fountain_clickontree");
        }
        public function onSymbolToInventory():void{
            triggerNewState(TutorialModel.FOUNTAIN_ZOOM_TO_ELDER, 3000);
            var _local1:String = world.getRoomIdsOfType(GameConstants.TYPE_FOUNTAIN)[0];
            var _local2:IMoving = (world.getActor("my_avatar") as IMoving);
            _local2.targetRoomId = _local1;
            _local2.checkMove();
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"f50_flower"}));
            tutorial.hideFocusArrow();
            tutorial.hideSpotlight();
            tutorial.showClickBlocker();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onZoomToElder():void{
            mapEvent(EventConstants.ZOOM_INTO_ROOM_COMPLETE, TutorialModel.FOUNTAIN_TREAT_ELDER);
            dispatch(new InfoEvent(EventConstants.ZOOM_IN_ROOM, String(getRoomSlotByType(GameConstants.TYPE_FOUNTAIN).id)));
        }
        public function onTreatElder():void{
            mapEvent(EventConstants.SHOW_POPUP, TutorialModel.FOUNTAIN_SHOW_TREAT_ELDER_BUBBLE);
            tutorial.showFocusArrow(130, 280, -90);
            tutorial.showBlockingSpotlight(380, 225, 1.1);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_fountain_clickonelder2");
        }
        public function onTreatElderBubble():void{
            mapEvent(EventConstants.SET_FOUNTAIN_STATE, TutorialModel.FOUNTAIN_WAIT_FOR_ELDER_TREATMENT);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"f60_elder_in_foy_ready"}));
        }
        public function onWaitForElderTreatment():void{
            mapEvent(EventConstants.FINISH_REGENERATION, TutorialModel.FOUNTAIN_RELEASE_ELDER);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"f70_start_fountain"}));
            tutorial.hideFocusArrow();
            tutorial.hideSpotlight();
            tutorial.showClickBlocker();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onReleaseElder():void{
            friendsModel.updateFriendsInCount = 0;
            dispatch(new Event(EventConstants.LOAD_DETAILS));
            dispatch(new InfoEvent(EventConstants.ZOOM_IN_ROOM, String(getRoomSlotByType(GameConstants.TYPE_FOUNTAIN).id)));
            eventMap.mapListener(eventDispatcher, EventConstants.FOUNTAIN_CLOSED, mapDestroyWindow);
            mapEvent(EventConstants.POST_ON_WALL, TutorialModel.FOUNTAIN_SHARE);
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"f80_baby_get_reward"}));
            tutorial.showFocusArrow(130, 280, -90);
            tutorial.showClickBlocker(380, 225, 1.1);
            tutorial.hideSpotlight();
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_fountain_getreward");
        }
        public function onShare():void{
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.TUTORIAL, {step:"f90_share_foy"}));
            tutorialModel.state = TutorialModel.FOUNTAIN_FINISH_TUTORIAL;
        }
        public function onFinish():void{
            roomSlotsModel.tempAvailableRoomSlots = 0;
            gameStateModel.state = GameStateModel.STATE_GAME_RUNNING;
            dispatch(new InfoEvent(EventConstants.INIT_MISSION));
            onRemoveOverlay();
            dispatch(new InfoEvent(EventConstants.CHECK_KINDERGARTEN_TUTORIAL, null, TutorialModel.KINDERGARTEN_CLICK_ON_SHOP));
            enableControls();
        }

    }
}//package net.wooga.pets.views.tutorial.chapter 
